﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Web;
using System.Web.Services;
using WMS.Service.tool;
using static WMS.Service.tool.HttpRequest;

namespace ErpWebService
{
    /// <summary>
    /// Service 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class Service : System.Web.Services.WebService
    {

        private string url = "http://47.102.132.52:8080/api/v3/";
        private static readonly ILog log = LogManager.GetLogger(typeof(Service));

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }


        /// <summary>
        /// 批量新增物料
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [WebMethod]
        public RequestErp ERP_ItemList(string data)
        {
            log.Info("批量新增物料:" + data);
            url = url+"materialOperation";
            JsonData jd = WMS.Service.tool.HttpRequest.Post(data, url);
            RequestErp re = new RequestErp();
            if (jd.code!=200)
            {
                re.Success = "2";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }
            else
            {
                re.Success = "1";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }

            return re;
        }
        
        /// <summary>
        /// 生产派工单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [WebMethod]
        public RequestErp ERP_ScInOrder(string data)
        {
            log.Info("生产派工单:" + data);
            url = url + "produceOrder";
            JsonData jd = WMS.Service.tool.HttpRequest.Post(data, url);
            RequestErp re = new RequestErp();
            if (jd.code != 200)
            {
                re.Success = "2";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }
            else
            {
                re.Success = "1";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }

            return re;
        }

        /// <summary>
        /// EAS采购入库单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [WebMethod]
        public RequestErp ERP_PoInOrder(string data)
        {
            log.Info("EAS采购入库单:" + data);
            url = url + "purchaseOrder";
            JsonData jd = WMS.Service.tool.HttpRequest.Post(data, url);
            RequestErp re = new RequestErp();
            if (jd.code != 200)
            {
                re.Success = "2";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }
            else
            {
                re.Success = "1";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }

            return re;
        }

        /// <summary>
        /// EAS调拨入库订单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [WebMethod]
        public RequestErp ERP_DbInOrder(string data)
        {
            log.Info("EAS调拨入库订单:" + data);
            url = url + "transferInOrder";
            JsonData jd = WMS.Service.tool.HttpRequest.Post(data, url);
            RequestErp re = new RequestErp();
            if (jd.code != 200)
            {
                re.Success = "2";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }
            else
            {
                re.Success = "1";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }

            return re;
        }

        /// <summary>
        /// EAS调拨出库订单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [WebMethod]
        public RequestErp ERP_DbOutOrder(string data)
        {
            log.Info("EAS调拨出库订单:" + data);
            url = url + "transferOutOrder";
            JsonData jd = WMS.Service.tool.HttpRequest.Post(data, url);
            RequestErp re = new RequestErp();
            if (jd.code != 200)
            {
                re.Success = "2";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }
            else
            {
                re.Success = "1";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }

            return re;
        }

        /// <summary>
        /// EAS领料出库订单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [WebMethod]
        public RequestErp ERP_LlOutOrder(string data)
        {
            log.Info("EAS领料出库订单:" + data);
            url = url + "requisitionOrder";
            JsonData jd = WMS.Service.tool.HttpRequest.Post(data, url);
            RequestErp re = new RequestErp();
            if (jd.code != 200)
            {
                re.Success = "2";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }
            else
            {
                re.Success = "1";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }

            return re;
        }
        
        /// <summary>
        /// EAS销售出库订单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [WebMethod]
        public RequestErp ERP_SalesOutOrder(string data)
        {
            log.Info("EAS销售出库订单:" + data);
            url = url + "salesOrder";
            JsonData jd = WMS.Service.tool.HttpRequest.Post(data, url);
            RequestErp re = new RequestErp();
            if (jd.code != 200)
            {
                re.Success = "2";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }
            else
            {
                re.Success = "1";
                re.Message = jd.msg;
                re.billErrors = jd.data.ToJson();
            }

            return re;
        }
    }
}
